export default {
	state: {
		userinfo: false,
		token: false,
		loginStatus: false
	},

	mutations: {
		//实现永久缓存  免登录功能 

		initUser(state) {
			// let userinfo = JSON.parse(uni.getStorageSync('userinfo'))
			// if (userinfo) {
			// 	state.userinfo = userinfo,
			// 		state.token = userinfo.token,
			// 		state.loginStatus = true
			// }
			
			  //提高代码的严谨性
			let  userinfo=uni.getStorageSync('userinfo')
			if(userinfo) {
				userinfo=JSON.parse(userinfo)
					state.userinfo = userinfo,
						state.token = userinfo.token,
						state.loginStatus = true
			}

		},





		login(state, userinfo) {
			console.log(userinfo)
			state.userinfo = userinfo
			state.token = userinfo.token
			state.loginStatus = true

			//设置本地缓存 实现 永久免登录功能
			uni.setStorageSync('userinfo', JSON.stringify(userinfo))
		},


		// 退出登录 
		myLogout(state) {
			state.loginStatus = false,
				state.token = false,
				state.userinfo = false

			uni.removeStorageSync('userinfo')
		}





	}


}
